# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=gvmd
pkgver=9.0.1
pkgrel=2
pkgdesc="Greenbone Vulnerability Manager"
url="https://www.openvas.org/"
arch="all"
license="GPL-2.0-or-later"
pkgusers="gvm"
pkggroups="gvm"
depends="rsync postgresql postgresql-contrib libxslt sed gnutls-utils gvm-libs perl-xml-twig"
makedepends="cmake gvm-libs-dev clang-dev glib-dev
	gpgme-dev libgcrypt-dev graphviz libical-dev
	postgresql-dev gnutls-dev
	doxygen xmltoman perl-sql-translator"
checkdepends="cppcheck"
subpackages="$pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/greenbone/gvmd/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.logrotate

	greenbone-certdata-sync.conf
	greenbone-scapdata-sync.conf
	greenbone-nvt-sync.conf

	added-missing-includes.patch
	bin-openvas-change.patch
	fix-alpine-sql-syntax.patch
	sys-siglist.patch
	fix-gvm-port-update-name-and-backend.patch
	lockfile.patch
	strptime.patch"

case "$CARCH" in
	# cppcheck is not available
	s390x|aarch64|mips|mips64) options="$options !check"
esac

prepare() {
	default_prepare
	mkdir build
}

build() {
	cd "$builddir"/build
	# Requires libexecinfo when compiled without -DNDEBUG.
	CFLAGS="$CFLAGS -DNDEBUG" \
		cmake -DCMAKE_BUILD_TYPE=None \
		-DSBINDIR=/usr/bin \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSYSCONFDIR=/etc \
		-DLOCALSTATEDIR=/var \
		-DGVM_RUN_DIR=/var/run/gvmd \
	..
	make
}

check() {
	cd "$builddir"/build
	make check
}

package() {
	cd "$builddir"/build
	make DESTDIR="$pkgdir" install
	install -Dm644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	for f in nvt certdata scapdata; do
		install -Dm755 "$srcdir"/greenbone-$f-sync.conf "$pkgdir"/etc/gvm/greenbone-$f-sync.conf
	done
	mkdir -p "$pkgdir"/var/log/gvm
	mkdir -p "$pkgdir"/var/lib/gvm
	mkdir -p "$pkgdir"/var/lib/openvas
	mkdir -p "$pkgdir"/var/run/gvmd
	chown -R $pkgusers:$pkggroups "$pkgdir"/var/log/gvm
	chown -R $pkgusers:$pkggroups "$pkgdir"/var/lib/gvm
	chown -R $pkgusers:$pkggroups "$pkgdir"/var/lib/openvas
	chown -R $pkgusers:$pkggroups "$pkgdir"/var/run/gvmd
}

doc() {
	default_doc
	mkdir -p "$subpkgdir"/usr/share/doc/$pkgname
	cat >"$subpkgdir"/usr/share/doc/$pkgname/README.alpine <<EOF
	** Add texlive to generate PDF reports with
	** apk add texlive
EOF
}


sha512sums="4c4f0e1fdd2255be1a96967d61d9066d8860aecc5959f04c559b1a248bcc54d9cb75facd0156e223d674f038718f1e8ba0ee6b36cdc8ed88efe480acd1aa54cf  gvmd-9.0.1.tar.gz
035a46a287dc87329c9f2fd436bbd822cbfea82752558dce356026ecacce1639169e147a7e683663df394c1b0b18576f4dfd72f42966a90ebd54c46cd7a75402  gvmd.initd
63ca41e839e40292e4e6eb93947866ae2626f375353dfc142a9618f5bfb87e843f924e5a2ab3f24b5c30ac1c7c8791a5b323cbe2e88fb3c4cfc9713647f8eec2  gvmd.confd
e1eeef173bfab7c750efcc7faa42cf7a1cfb9e6b137716063f273bc709c1346f11262dadbdb0c49822d885dc00177d8ccb91c0491ddc33cfee0a3827f11908f6  gvmd.logrotate
17df9386fc1dccf2fbe3b8d1fd499171f6681b61afe7b4c11ff9debc008798b31d1d02d59463031482d94e10833f0e71bde27cbbe422f23738c77b7c6ada79d2  greenbone-certdata-sync.conf
37dbbd3f92f8baee8e89c274d820e03cba5ed5469a826f118897035c2f7719a915a71a6069eb6bf7f9a72e798b7837af9a6f25709215683d9d264292b5ccad66  greenbone-scapdata-sync.conf
964779adc39cbed191bccf02ccc408a263860002d2dbddee755cf0d015336814b0b3c83f88a02cc0c5959657be5c49eb94380cd6ba15844e4b6088e49cd7a3f0  greenbone-nvt-sync.conf
b5411a618e62e5a64fae3441d7f8a4db1fb7675200d8ce5f8208b09c6459b33920f3a65519c8d17781929917eeb4966e60701e64612c6cfcb77101130f779992  added-missing-includes.patch
8d711e7411c92aaa1fb7d2cb3bce1aae80e8843703fca15dcac202619907589e43ef0575e26470e075d6517bca150b777b1fa1afd32f900ca3e36537bacb17e4  bin-openvas-change.patch
5b7645912e107f67e1cc64cdb817404bc5212c41328201cfcc048a3ee73cf3c135b5128f1da6e84946ddc9361751b3da92518e493d940c2bbbda0c8ada8f3d5f  fix-alpine-sql-syntax.patch
682ae0efb02c565ed28d67c3adc5d181fb0ac43d670573f0d9587cb6ff9d4dd89eaf1f43f0fab3928e447bee735958afec0f31c70f5ceffac3c68633469ff71a  sys-siglist.patch
981c4cb32e5ef46be97b0c2d3cb24ab8b49226212104eb56c49216d976a5ae3cda3518e7629c0417dd22c94cf2fe19c34b6a5d4efd291c06747db84e7be76596  fix-gvm-port-update-name-and-backend.patch
ef23f5bb64371f4e11eae0830a0c7a6a6463b792b2907cbc0527b1cf5a273927f676a254634ee3228315b44b6ca56716d3dce122dd43937fed79f2a443ae2d3d  lockfile.patch
e9c2717eacf852e6a08050245eff79cf917875c6e403bc1558c3dd02239fb07ad7d3ccd18978ce1b80f035077124c7d6049c75a587bd9609869861bdeb6aaba1  strptime.patch"
